<template>
    <h3 style="text-align: center;" >
        用户登录页面
    </h3>
    <table class="table table-bordered" border="1">
        <tr>
            <td>
                用户名
            </td>
            <td>
                <input type="text" v-model="Info.P_Name" placeholder="请输入用户名">
            </td>
        </tr>
        <tr>
            <td>
                密码
            </td>
            <td>
                <input type="password" v-model="Info.P_Pwd" placeholder="请输入密码">
            </td>
        </tr>
        <tr style="text-align: center;">
            <td colspan="2">
                <button class="btn btn-primary" @click="Adduser">登录</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
import {useStore}from '../../store/index.ts'
const store=useStore()
import { ref } from 'vue';
//双向绑定
const Info=ref({
    P_Id:0,
    P_Name:'',
    P_Pwd:'',
    P_State:'',


})
import axios from 'axios';
//登录
const Adduser=()=>{
    axios.get('https://localhost:44369/api/Peoples/Puserlogin',
    {
       params:{
        P_Name:Info.value.P_Name,
        P_Pwd:Info.value.P_Pwd
       }
    }).then((res)=>{
       
      if(res.data!=null)
      {
         //记录状态
         store.P_State=res.data.P_State

        //查询pinia状态
        if(store.P_State=="已经登录")
        {
            alert("用户已登录")
            router.push({
                path:'/ShowYonghxinx',
                query:{
                    P_Id:res.data.P_Id
                }
            })
        }
        else{
            alert("登录成功")
            router.push({
                path:'/AddPeopleLogin'
            })
        }
      }
      else{
        alert("登录失败")
      }
        console.log(res);
    })
}
</script>